/**
 * @description 
 */
const Shop = require('../models/Shop')
const Product = require('../models/Product')
/**
 * 热门商品列表
 * @returns Shop Array
 */
async function getHotList() {
  const shopList = await Shop.find().sort({ _id: -1 })
  return shopList
}
/**
 * 根据id获取单个商店信息
 * @param {String} id 
 * @returns Shop
 */
async function getShopById(id) {
  const once = await Shop.findById(id)
  return once
}
/**
 * 根据商店id和商品分类获取商品列表
 * @param {String} id 
 * @param {String} tab 
 * @returns Product Array
 */
async function getProductByShopId(id, tab = '') {
  const productList = await Product.find({
    shopId: id,
    tabs: {
      $in: tab
    }
  }).sort({ _id: -1 })
  return productList
}
module.exports = { getHotList, getShopById,getProductByShopId }

